package cn.edu.scau.cmi.ema.domain;


import com.alibaba.fastjson.annotation.JSONField;

import javax.persistence.*;
import javax.xml.bind.annotation.*;
import java.io.Serializable;

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllFillerfillers", query = "select myFillerfiller from Fillerfiller myFillerfiller"),
		@NamedQuery(name = "findFillerfillerByName", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.name = ?1"),
		@NamedQuery(name = "findFillerfillerByNameContaining", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.name like concat('%',?1,'%')"),
		@NamedQuery(name = "findFillerfillerBySimilarity", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.similarity = ?1"),
		@NamedQuery(name = "findFillerfillerBySimilarityContaining", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.similarity like concat('%',?1,'%')"),
		@NamedQuery(name = "findFillerfillerByDescription", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.description = ?1"),
		@NamedQuery(name = "findFillerfillerByDescriptionContaining", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.description like concat('%',?1,'%')"),
		@NamedQuery(name = "findAllFillerfillersByOther", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.other.id = ?1"),
		@NamedQuery(name = "findAllFillerfillersBySelf", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.self.id = ?1"),
		@NamedQuery(name = "findFillerfillerById", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.id = ?1"),
		@NamedQuery(name = "findFillerfillerByPrimaryKey", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.id = ?1 "),
		@NamedQuery(name = "deleteFillerfillersByIds", query = "delete Fillerfiller where id in (?1)"),
		@NamedQuery(name = "findFillerfillersByIds", query = "select myFillerfiller from Fillerfiller myFillerfiller where myFillerfiller.id in (?1)"),
		@NamedQuery(name = "findFillerfillerByPhyscialPrimaryKey", query = "select myFillerfiller from Fillerfiller myFillerfiller where  myFillerfiller.self.id = ?1 and myFillerfiller.other.id = ?2"),
		@NamedQuery(name = "countFillerfillersByName", query = "select count(myFillerfiller)  from Fillerfiller myFillerfiller where myFillerfiller.name like concat('%',?1,'%')") })
@Table(catalog = "ema", name = "fillerfiller")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "ema/cn/edu/scau/cmi/ema/domain", name = "Fillerfiller")
@XmlRootElement(namespace = "ema/cn/edu/scau/cmi/ema/domain")

public class Fillerfiller implements Serializable, Comparable<Fillerfiller> {

	private static final long serialVersionUID = 1L;

	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@XmlElement
	Integer id;

	@Column(name = "name")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String name;

	@Column(name = "similarity")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String similarity;

	@Column(name = "description")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String description;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "other", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Filler other;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "self", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Filler self;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return this.id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setSimilarity(String similarity) {
		this.similarity = similarity;
	}

	public String getSimilarity() {
		return this.similarity;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return this.description;
	}

	public void setOther(Filler other) {
		this.other = other;
	}

	public Filler getOther() {
		return other;
	}

	public void setSelf(Filler self) {
		this.self = self;
	}

	public Filler getSelf() {
		return self;
	}

	public void copy(Fillerfiller that) {

		setId(that.getId());

		setName(that.getName());
		setSimilarity(that.getSimilarity());
		setDescription(that.getDescription());

		setOther(that.getOther());

		setSelf(that.getSelf());

	}

	public Fillerfiller() {

	}

	@Override
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");

		buffer.append("name=[").append(name).append("] ");
		buffer.append("similarity=[").append(similarity).append("] ");
		buffer.append("description=[").append(description).append("] ");

		return buffer.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Fillerfiller))
			return false;
		Fillerfiller comparedFillerfiller = (Fillerfiller) obj;
		if (!CheckPropertyEqual(this.self.id, comparedFillerfiller.self.id)) {
			return false;
		}
		if (!CheckPropertyEqual(this.other.id, comparedFillerfiller.other.id)) {
			return false;
		}
		return true;
	}

	public static <T> boolean CheckPropertyEqual(T originProperty, T comparedProperty) {
		// 基本类型经过参数传递后会自动装箱
		String[] className = originProperty.getClass().getName().split("\\.");
		if (className[0].equals("java") && className[1].equals("math")) {
			return ((Comparable) originProperty).compareTo(comparedProperty) == 0 ? true : false;
		} else {
			return originProperty.equals(comparedProperty);
		}
	}

	@Override
	public int compareTo(Fillerfiller o) {
		if (this.getId() > o.getId()) {
			return 1;
		} else if (this.getId() == o.getId()) {
			return 0;
		} else {
			return -1;
		}

	}
}
